/*
 * @Description: aes
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2021-09-17 14:24:34
 * @LastEditors: ziwei
 * @LastEditTime: 2021-09-17 15:06:45
 */
let crypto = require('crypto');
function encrypt(data,key,iv) {
  let cipher = crypto.createCipheriv('aes-128-cbc',key,iv);cipher.update(data);
  return cipher.final('hex');//16进制的意思 把结果输出成16进制的字符串
}

function decrypt(data,key,iv){
  let cipher = crypto.createDecipheriv('aes-128-cbc',key,iv);cipher.update(data,'hex');//16进制的意思 把结果输出成16进制的字符串
  return cipher.final('utf8');//输出成utf8字符
}

let key = '1234567890123456';
let iv ='1234567890123456';
let data = "hello";
let encryptedData = encrypt(data,key,iv);
console.log(encryptedData);
let decryptedData = decrypt(encryptedData,key,iv);
console.log(decryptedData);
